<?php
/**
*
* @package shopBB
* @copyright (c) 2008 EXreaction, Lithium Studios
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/* Notes
* Cart
* Bidding/Auctions
* Special Items
* Ratings
* Re-setup URLs.  Use SEO urls for the category/item name, non-seo for the rest.
* Rebuild the ACP - Currently it is just copied from the User Blog Mod.
* Coupons!  Separate coupon table where a user can enter coupon codes (or generate?) for items he has added or special board-wide coupons
*
* DO NOT FORGET
* - Uncomment out the UNINSTALL BLOCK line before releasing.
* - Set shop_seo to false for the default
* - Update link in ACP to check for new version ~line 223 & ~line 230
*/

if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', '../');
if (!defined('SHOPBB_PATH')) define('SHOPBB_PATH', PHPBB_ROOT_PATH . 'shop/');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));

// required for phpBB 3.0.x
$phpbb_root_path = PHPBB_ROOT_PATH;
$phpEx = PHP_EXT;

// phpBB Integration stuff
define('IN_PHPBB', true);
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
$user->session_begin();
$auth->acl($user->data);
$user->setup();

include(SHOPBB_PATH . 'constants.' . PHP_EXT);
include(SHOPBB_PATH . 'shop_class.' . PHP_EXT);
include(SHOPBB_PATH . 'functions.' . PHP_EXT);
include(SHOPBB_PATH . 'plugins/plugins.' . PHP_EXT);

// Redirect to the installation page
if (!isset($config['shopbb_version']))
{
	redirect(append_sid(SHOPBB_PATH . 'database.' . PHP_EXT));
}

new shop();
shop::add_lang('shop');

if (!$config['shop_enabled'])
{
	trigger_error('SHOP_DISABLED');
}

new shop_plugins();

$page = request_var('page', '');
$mode = request_var('mode', '');

shop_plugins::plugin_do('start');

// What page shall we display?
$include = 'pages/index';
switch ($page)
{
	/* When adding more pages to this list make sure to add it to the reserved item names (both the page and mode) in shop::submit_item() */
	case 'item' :
		switch ($mode)
		{
			case 'add' :
			case 'edit' :
			case 'delete' :
			case 'purchase' :
				$include = 'pages/item/' . $mode;
			break;
		}
	break;

	default :
		extract(shop_plugins::plugin_do('page_select', compact('include', 'page', 'mode')));
	break;
}

include(SHOPBB_PATH . $include . '.' . PHP_EXT);

// Some extra stuff
$template->assign_vars(array(
	'MINI_POST_IMG'		=> '',
));

// Add our credits...
$user->lang['TRANSLATION_INFO'] = (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] . '<br />' . $user->lang['SHOPBB_CREDITS'] : $user->lang['SHOPBB_CREDITS'];

shop_plugins::plugin_do('end');

page_footer();

?>